/**
 * $Id: Main.java 14 2011-02-01 08:06:29Z andriusms $
 */
package com.googlecode.kanjicards;

import com.googlecode.kanjicards.entity.Vocabulary;
import com.googlecode.kanjicards.format.A4CheatSheet;
import com.googlecode.kanjicards.format.Renderable;
import com.googlecode.kanjicards.format.RenderingException;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.xml.Unmarshaller;

import java.io.FileInputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            Renderable outputFormat = new A4CheatSheet();

            Mapping mapping = new Mapping();
            mapping.loadMapping(Main.class.getResource("/mapping.xml"));
            Unmarshaller unmarshaller = new Unmarshaller(mapping);
            InputStreamReader fstream = new InputStreamReader(new FileInputStream("input/kanji.xml"), "UTF-8");
            Vocabulary vocabulary = (Vocabulary) unmarshaller.unmarshal(fstream);

            outputFormat.render(vocabulary, "output/a4.pdf");

            System.out.println("Rendering done!");
        } catch (RenderingException re) {
            System.out.println("Rendering failed: " + re.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
